// pages/teacher/profile/profile.js
import { logout } from '../../../utils/auth.js'

Page({
  data: {
    userInfo: {
      name: '张老师',
      avatar: '/images/teacher1.jpg',
      level: '高级讲师',
      isVerified: true,
      introduction: '10年教学经验，精通小程序开发'
    },
    stats: {
      courses: 12,
      students: 856,
      revenue: 15230
    },
    menuSections: [
      {
        title: '教学管理',
        items: [
          { icon: '📚', text: '我的课程', url: '/pages/teacher/my-courses/my-courses' },
          { icon: '📝', text: '作业管理', url: '/pages/teacher/homework/homework' },
          { icon: '❓', text: '试题库', url: '/pages/teacher/question-bank/question-bank' },
          { icon: '🎥', text: '直播管理', url: '/pages/teacher/live-room/live-room' }
        ]
      },
      {
        title: '数据统计',
        items: [
          { icon: '📊', text: '学情数据', url: '/pages/teacher/student-data/student-data' },
          { icon: '💰', text: '收益管理', url: '/pages/teacher/revenue/revenue' },
          { icon: '📈', text: '数据报表', url: '' }
        ]
      },
      {
        title: '个人设置',
        items: [
          { icon: '👤', text: '个人信息', url: '/pages/teacher/edit-profile/edit-profile' },
          { icon: '🔔', text: '消息通知', url: '' },
          { icon: '⚙️', text: '系统设置', url: '' }
        ]
      }
    ]
  },
  onLoad() {
    this.loadUserInfo()
  },
  onShow() {
    this.loadUserInfo()
  },
  loadUserInfo() {
    const userInfo = wx.getStorageSync('userInfo')
    if (userInfo) {
      this.setData({ userInfo })
    }
  },
  navigateTo(e) {
    const url = e.currentTarget.dataset.url
    if (url) {
      wx.navigateTo({ url })
    } else {
      wx.showToast({
        title: '功能开发中',
        icon: 'none'
      })
    }
  },
  goToEditProfile() {
    wx.navigateTo({
      url: '/pages/teacher/edit-profile/edit-profile'
    })
  },
  handleLogout() {
    wx.showModal({
      title: '退出登录',
      content: '确定要退出登录吗？',
      confirmColor: '#ff5722',
      success: (res) => {
        if (res.confirm) {
          logout()
        }
      }
    })
  }
})
